package edu.umassd.visual.options;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.annotation.PostConstruct;
import javax.swing.JComboBox;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import edu.umassd.visual.DataPoints;
import edu.umassd.visual.View;

@Component("y-axis")
public class YAxisSelector extends JComboBox<String> implements ActionListener
{
	private static final long serialVersionUID = 932532308442493721L;

	@Autowired
	private DataPoints data;

	@Autowired
	private View view;

	@PostConstruct
	protected void register()
	{
		this.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		JComboBox<?> box = (JComboBox<?>) e.getSource();

		data.setYIndex(box.getSelectedIndex());

		view.setDataSetBounds(data.getBounds());
		view.fitToScreen();
	}
}